package com.jinken.component;

import com.alibaba.cloud.commons.lang.StringUtils;
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Component;

@Component
public class HeaderOriginParser implements RequestOriginParser {
    /**
     * Sentinel 获取并判断请求头是否有origin
     * @param request
     * @return
     */
    @Override
    public String parseOrigin(HttpServletRequest request) {

        //获取请求头是否origin头信息
        String origin = request.getHeader("origin");
        if(StringUtils.isEmpty(origin)){
            return "blank";
        }
        return origin;
    }
}
